﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Jzy.UI.Web.Areas.Site.Models;
using System.Text;
using Jzy.UI.Web.Areas.Site.BaseCode;
using System.Web.Routing;
using Frame.Lib.Core.Company;
using Cms.BLL.Article;
using Cms.Entity.Article;
using Cms.BLL.FreindLink;
using Cms.Entity.FreindLink;


namespace Jzy.UI.Web.Areas.Site.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            CompanyBO company = new CompanyBO();
            CompanyInfo info = company.GetList().First();

            string str = (this.ControllerContext.RouteData.Route as Route).Url;
            string uri = Request.Url.AbsoluteUri;            
            if (uri.Contains("betop.sh.cn"))
            {
                Response.Redirect("/betop/index.html");
                Response.End();
            }
           // return Content((info == null).ToString());
            return View(SitePath.Views + "Home/Index.aspx",info);
        }

      

        public ActionResult About()
        {
            ArticleBO article = new ArticleBO();
            IEnumerable<ArticleInfo> list = article.GetDisplayListByCode(1, 1);
            if (list.Count() > 0)
            {
                ViewData["Content"] = list.First().Content;
            }
            else
            {
                ViewData["Content"] = "";
            }

            return View(SitePath.Views + "Shared/About.ascx");
        }

        [ChildActionOnly]
        public ActionResult Top(string index)
        {
            this.ViewData["index"] = index;
            return View(SitePath.Views + "Shared/Top.ascx");
        }


        public ActionResult Design()
        {
            ArticleBO article = new ArticleBO();
            IEnumerable<ArticleInfo> list3 = article.GetDisplayListByCode(3, 8);


            IEnumerable<ArticleInfo> list4 = article.GetDisplayListByCode(4, 8);

            DesignModel model = new DesignModel { List3 = list3, List4 = list4 };
            return View(SitePath.Views + "Shared/Design.ascx", model);
        }

        public ActionResult FreindLink()
        {
            FreindLinkBO freindLink = new FreindLinkBO();
            IEnumerable<FreindLinkInfo> list = freindLink.GetList();
            return View(SitePath.Views + "Shared/FreindLink.ascx", list);
        }

        public ActionResult News()
        {
            ArticleBO article = new ArticleBO();

            IEnumerable<ArticleInfo> list = article.GetDisplayListByCode(11, 8);

            return View(SitePath.Views + "Shared/News.ascx", list);
        }

        public ActionResult Bottom()
        {
            CompanyBO company = new CompanyBO();
            CompanyInfo info = company.GetList().First();

            ViewData["IPC"] = info.SiteIPC;
            return View(SitePath.Views + "Shared/Bottom.ascx");
        }

        public ActionResult Contact()
        {
            CompanyBO company = new CompanyBO();
            CompanyInfo info = company.GetList().First();
            return View(SitePath.Views + "Shared/Contact.ascx", info);
        }

        public ActionResult ContactUs()
        {
            CompanyBO company = new CompanyBO();
            CompanyInfo info = company.GetList().First();
            return View(SitePath.Views + "Home/ContactUs.aspx", info);
        }

        public void Photos()
        {
            ArticleBO article = new ArticleBO();
            IEnumerable<ArticleInfo> list = article.GetDisplayListByCode(10, 11);

            StringBuilder str = new StringBuilder();
            str.Append("<?xml version='1.0'?>");
            str.Append("<photos path=''>");
            int i = 1;
            foreach (ArticleInfo info in list)
            {
                str.Append("<photo id='photo" + i + "' name='photo" + i + "' url='" + info.SmallImageAbsPath + "' linkurl='" + info.BigImageAbsPath + "'/>");
                i++;
            }
            str.Append("</photos>");
            Response.Write(str.ToString());
            Response.End();

        }

    }
}
